package com.aptemo.webetek.client.widgets.dialogs;

import com.aptemo.webetek.client.Webetek;
import com.aptemo.webetek.client.events.DecisionEvent;
import com.aptemo.webetek.client.events.DecisionHandler;
import com.aptemo.webetek.client.events.HasDecisionHandlers;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.Widget;

public class JoinTeamDialog
		extends DialogBox implements HasDecisionHandlers
{

	private static JoinTeamDialogUiBinder	uiBinder	= GWT.create(JoinTeamDialogUiBinder.class);

	interface JoinTeamDialogUiBinder extends UiBinder<Widget, JoinTeamDialog>
	{
	}

	@UiField
	Label		infoField;

	@UiField
	Button		cancelButton;

	@UiField
	TextArea	joinMessageField;

	// private WebetekConstants i18n = GWT.create(WebetekConstants.class);
	// private Button mcreateGroupButton = new Button("Submit");
	// private Button mcancelButton = new Button("Cancel");
	// private Label minfolabel = new Label(i18n.createGroupDialogInfo());
	// private TextBox mnameEdit = new TextBox();
	// private CheckBox mcheckbox = new CheckBox();
	// private String mid;

	public JoinTeamDialog(String teamTitle)
	{
		this.add(uiBinder.createAndBindUi(this));
		setText(Webetek.getMessages().joinTeamTitle(teamTitle));
	}

	@Override
	public HandlerRegistration addDecisionHandler(DecisionHandler handler)
	{
		return addHandler(handler, DecisionEvent.TYPE);
	}

	@UiHandler("submitButton")
	void onSubmitClick(ClickEvent event)
	{
		// check email field
		infoField.setText("");
		hide();

		// fire event...
		DecisionEvent dev = new DecisionEvent(infoField);
		fireEvent(dev);

	}

	@UiHandler("cancelButton")
	void cancelHandler(ClickEvent event)
	{
		hide();
	}

	public HasText getJoinNoteField()
	{
		return joinMessageField;
	}

	@Override
	public void center()
	{
		super.center();
		infoField.setText("");
	}

}
